package com.scs.application.modules.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.scs.application.core.exception.BusinessException;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.base.entity.Distributor;
import com.scs.application.modules.base.mapper.DistributorMapper;
import com.scs.application.modules.base.service.DistributorService;
import com.scs.application.core.service.BaseServiceImpl;
import org.springframework.stereotype.Service;
/**
 * <p>
 *  服务实现类
 * </p>
 */
@Service
public class DistributorServiceImpl extends BaseServiceImpl<DistributorMapper, Distributor> implements DistributorService {

    @Override
    public boolean saveOrUpdate(Distributor entity) {

        Distributor distributor = super.getOne(new QueryWrapper<Distributor>().eq("name", entity.getName()).ne(StringUtils.isNotEmpty(entity.getId()), "id", entity.getId()));
        if (distributor != null) {
            throw new BusinessException("配送商名称不能重复!");
        }
        return super.saveOrUpdate(entity);
    }
}
